var CANVAS_HEIGHT = 224;
var CANVAS_WIDTH = 2*224;

var FIXED_UPDATES_IN_A_SECOND = 30;
var FIXED_STEP_IDEAL_DURATION_MS = 1000/FIXED_UPDATES_IN_A_SECOND;

var WALK_SPEED_PIXELS_PER_SECOND = 70;
var WALK_SPEED_PIXELS_PER_UPDATE = WALK_SPEED_PIXELS_PER_SECOND/FIXED_UPDATES_IN_A_SECOND;

var BACKGROUND_IMG = new Image();
BACKGROUND_IMG.src = "img/TMNT-City.png";

var SPRITE_CATALOG_DONNIE = new Image();
//SPRITE_CATALOG_DONNIE.src = "img/donnie_debug.png";
SPRITE_CATALOG_DONNIE.src = "img/donnie.png";

//stand crops:
var SPRITE_SHEET_CROPPED_FRAME_01 = new ImgCrop(10, 103, 0, 0, 78, 98);
var SPRITE_SHEET_CROPPED_FRAME_02 = new ImgCrop(82, 103, 0, 0, 78, 98);
var SPRITE_SHEET_CROPPED_FRAME_03 = new ImgCrop(158, 103, 0, 0, 78, 98);
//crouch crops:
var SPRITE_SHEET_CROPPED_FRAME_37 = new ImgCrop(400, 934, -18, 2, 107, 100);
//punch crops:
var SPRITE_SHEET_CROPPED_FRAME_10 = new ImgCrop(466, 205, 0, 0, 80, 98);
//simple kick crops:
var SPRITE_SHEET_CROPPED_FRAME_04 = new ImgCrop(452, 103, -24, 0, 110, 98);
var SPRITE_SHEET_CROPPED_FRAME_05 = new ImgCrop(5, 202, -24, 0, 110, 98);
//roundhouse kick crops:
var SPRITE_SHEET_CROPPED_FRAME_06 = new ImgCrop(117, 202, -15, 0, 90, 98);
var SPRITE_SHEET_CROPPED_FRAME_07 = new ImgCrop(212, 203, 22, 0, 80, 98);
var SPRITE_SHEET_CROPPED_FRAME_08 = new ImgCrop(300, 205, 3, 0, 70, 98);
//staff kata crops:
var SPRITE_SHEET_CROPPED_FRAME_19 = new ImgCrop(443, 656, 13, 21, 130, 80);
var SPRITE_SHEET_CROPPED_FRAME_20 = new ImgCrop(48, 762, 8, 21, 130, 80);
var SPRITE_SHEET_CROPPED_FRAME_21 = new ImgCrop(175, 762, 8, 20, 124, 80);
var SPRITE_SHEET_CROPPED_FRAME_22 = new ImgCrop(295, 762, 9, 19, 130, 80);
var SPRITE_SHEET_CROPPED_FRAME_23 = new ImgCrop(422, 762, 9, 17, 130, 80);
var SPRITE_SHEET_CROPPED_FRAME_24 = new ImgCrop(18, 860, 9, 22, 130, 80);
var SPRITE_SHEET_CROPPED_FRAME_25 = new ImgCrop(160, 860, 9, 22, 114, 80);
var SPRITE_SHEET_CROPPED_FRAME_26 = new ImgCrop(270, 860, 4, 20, 117, 80);
//heliKick crops:
var SPRITE_SHEET_CROPPED_FRAME_27 = new ImgCrop(500, 937, 10, 1, 107, 100);
var SPRITE_SHEET_CROPPED_FRAME_28 = new ImgCrop(8, 1048, 34, 30, 70, 70);
var SPRITE_SHEET_CROPPED_FRAME_29 = new ImgCrop(82, 1048, 36, 32, 70, 70);
var SPRITE_SHEET_CROPPED_FRAME_30 = new ImgCrop(149, 1048, 26, 32, 92, 70);
var SPRITE_SHEET_CROPPED_FRAME_31 = new ImgCrop(235, 1048, 3, 33, 125, 70);
var SPRITE_SHEET_CROPPED_FRAME_32 = new ImgCrop(360, 1048, 14, 34, 96, 70);
var SPRITE_SHEET_CROPPED_FRAME_33 = new ImgCrop(450, 1048, 34, 34, 56, 70);
var SPRITE_SHEET_CROPPED_FRAME_34 = new ImgCrop(507, 1048, 31, 35, 80, 70);
var SPRITE_SHEET_CROPPED_FRAME_35 = new ImgCrop(0, 1152, 2, 41, 122, 70);
var SPRITE_SHEET_CROPPED_FRAME_36 = new ImgCrop(126, 1152, 10, 41, 96, 70);
//staffSwirl crops:
var SPRITE_SHEET_CROPPED_FRAME_11 = new ImgCrop(0, 318, -23, 12, 85, 90);
var SPRITE_SHEET_CROPPED_FRAME_12 = new ImgCrop(93, 318, -25, 13, 117, 90);
var SPRITE_SHEET_CROPPED_FRAME_13 = new ImgCrop(205, 318, -13, 14, 85, 120);
var SPRITE_SHEET_CROPPED_FRAME_14 = new ImgCrop(298, 318, -14, 16, 142, 120);
var SPRITE_SHEET_CROPPED_FRAME_15 = new ImgCrop(451, 318, -12, 14, 140, 90);
var SPRITE_SHEET_CROPPED_FRAME_16 = new ImgCrop(0, 435, -18, 16, 150, 90);
var SPRITE_SHEET_CROPPED_FRAME_17 = new ImgCrop(156, 415, -5, -10, 120, 120);
var SPRITE_SHEET_CROPPED_FRAME_18 = new ImgCrop(271, 415, -13, -11, 120, 120);

//see GameEntity.statesHistory
var STATES_HISTORY_CAPACITY = 10;

var USER_INPUT_BUFFER_CAPACITY = 10;

var ANIMATION_MANAGER = new AnimationManager();

var INPUT_EVENT_TYPE = {
	"punch":10,
	"kick":20,
	"right":30,
	"left":40,
	"down":50
};

var INPUT_EVENT_STATE = {
	"start":1,
	"end":0
};

var KEY_BINDINGS = {
		//o:
		79:INPUT_EVENT_TYPE.punch,
		//p:
		80:INPUT_EVENT_TYPE.kick,
		//s:
		83:INPUT_EVENT_TYPE.down,
		//d:
		68:INPUT_EVENT_TYPE.right,
		//a:
		65:INPUT_EVENT_TYPE.left		
};


function resetUPS(ups) {
	FIXED_UPDATES_IN_A_SECOND = ups;
	FIXED_STEP_IDEAL_DURATION_MS = 1000/FIXED_UPDATES_IN_A_SECOND;
	
	WALK_SPEED_PIXELS_PER_UPDATE = WALK_SPEED_PIXELS_PER_SECOND/FIXED_UPDATES_IN_A_SECOND;
}

